import { Router, Request, Response } from 'express';
import { 
    login, 
    logout, 
    getUserInfo,
    changePassword 
} from './controller';
import { getCaptcha, CaptchaRequest } from './captcha';
import { globalAuthMiddleware } from '../../middleware/auth';
import { AuthRequest } from '../../types/auth';
import { ChangePasswordBody } from '../../types/password';

const router = Router();

// 无需认证的路由
router.post('/login',login);
router.get('/captcha', (req: Request, res: Response) => getCaptcha(req as CaptchaRequest, res));
// 需要认证的路由
router.post('/logout',  logout);
router.get('/user/info',  (req, res) => getUserInfo(req as AuthRequest, res));
router.post('/password',  (req: Request, res: Response) => 
    changePassword(req as AuthRequest & { body: ChangePasswordBody, session: { user: Required<AuthRequest['session']['user']> } }, res)
);

export default router; 